! function(t, e) {
	"object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = t || self)
		.DragDOM = e()
}(this, function() {
	"use strict";

	function E(t, e) {
		return t.currentStyle ? t.currentStyle[e] : window.getComputedStyle(t, !1)[e]
	}
	return function() {
		function t(t) {
			var e = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : {};
			1 === t.nodeType ? (this.elPosition = E(t, "position"), "absolute" === this.elPosition || "fixed" === this.elPosition ? (this.el = t, this.parentData = null, this.elData = null, this.moveData = null, this.config = {
				overflow: e.overflow || !1,
				pUnit: e.pUnit || "px",
				start: e.start || function() {},
				drag: e.drag || function() {},
				end: e.end || function() {}
			}, this.init(this.el)) : console.warn("[DragDOM el] position on  absolute | fixed！")) : console.warn("[DragDOM el] Is not a valid node ！")
		}
		var e = t.prototype;
		return e.init = function(f) {
			var t, e, n, u = this,
				c = !1,
				o = void 0 !== f.ontouchstart ? "touch" : "mouse";

			function d(t) {
				var e = t || window.event;
				return "touch" === o ? e.touches[0] : e
			}
			n = "touch" === o ? (t = "touchstart", e = "touchmove", "touchend") : (t = "mousedown", e = "mousemove", "mouseup");
			var h, p, g, m, v, y, D, x, w, P, L, b, T = null;
			f.addEventListener(t, function(t) {
				if (t.preventDefault(), this.elPosition = E(f, "position"), "absolute" !== this.elPosition && "fixed" !== this.elPosition) return console.error("[Drag el] position on  absolute | fixed！");
				var e, n, o, i, s = d(t);
				w = s.pageX, P = s.pageY, y = "absolute" === u.elPosition ? (e = function(t) {
						for (var e = t.offsetLeft, n = t.offsetTop, o = t.offsetParent; null != o;) e += o.offsetLeft + o.clientLeft, n += o.offsetTop + o.clientTop, o = o.offsetParent;
						return {
							x: e,
							y: n
						}
					}(T = f.offsetParent), o = (n = T.getBoundingClientRect())
					.height, i = n.width, D = e.y, x = e.x, v = i, o) : (L = document.documentElement.clientWidth, b = document.documentElement.clientHeight, T = document.documentElement, x = D = 0, v = L, b), u.parentData = {
					parent: T,
					parentWidth: v,
					parentHeight: y,
					parentTop: D,
					parentLeft: x
				};
				var a = f.getBoundingClientRect(),
					l = a.height,
					r = a.width;
				g = r, m = l, h = f.offsetTop, p = f.offsetLeft, u.elData = {
					elWidth: g,
					elHeight: m,
					elTop: h,
					elLeft: p
				}, u.moveData = null, c = !0, u.config.start.call(u, t)
			}, !1), document.addEventListener(e, function(t) {
				var e, n, o, i, s;
				c && (t.preventDefault(), n = (e = d(t))
					.pageX - w, o = e.pageY - P, i = h + o, s = p + n, u.config.overflow || (y - m < i && (i = y - m), v - g < s && (s = v - g), i < 0 && (i = 0), s < 0 && (s = 0)), !(u.moveData = {
						mx: n,
						my: o,
						ely: i,
						elx: s
					}) !== u.config.drag.call(u, t, u.moveData) && (f.style.bottom = "auto", f.style.right = "auto", "%" === u.config.pUnit ? (f.style.top = i / y * 100 + "%", f.style.left = s / v * 100 + "%") : (f.style.top = i + "px", f.style.left = s + "px")))
			}, {
				passive: !1
			}), document.addEventListener(n, function(t) {
				c && (c = !1, u.config.end.call(u, t))
			}, !1)
		}, e.start = function(t) {
			return this.config.start = t, this
		}, e.drag = function(t) {
			return this.config.drag = t, this
		}, e.end = function(t) {
			return this.config.end = t, this
		}, t
	}()
});